#include <iostream>
#include "TxGrpc.h"

int main(int argc, char *argv[])
{
    TxGrpc::sptr grpc = TxGrpc::create();
#if 0
    grpc->SetSSLKey("./server.crt", "./server.key", "./client.crt", "./client.key", "65005077.txgang.com");
#endif
    int listenPort = 50053;
    grpc->StartServer(listenPort, 1, 1);
    grpc->SetServerRecvDataCallback([](const std::string &data, const std::string &peer, TxGrpc::SENDER sender){
        std::string s = "echos: " + data;
        std::cout <<"peer : "<<peer<<", data : "<<data << std::endl;
        sender(s);
    });

    std::cout<<"listen on port : "<<listenPort<<std::endl;
    
    while(1)
    {
        std::string line;
        std::getline(std::cin, line);
        if(line == "exit")
        {
            break;
        }
    }

    grpc->StopServer();
    getchar();
    grpc.reset();

    return 0;
}